﻿using MarkDownFileSplitter.AIAnalaysis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace MarkDownFileSplitter.AIDelete
{
    internal class AIDeleteConent
    {
        public int[] Find(Markdown.MarkdownFileContent m_currentContent)
        {
            StringBuilder stringBuilder = new StringBuilder();
            int fromIndex = 0;
            for (var i = 0; i < m_currentContent.ContentLines.Length; i++)
            {
                var line= m_currentContent.ContentLines[i];
                var nline = Regex.Replace(line, " ", "").Trim();
                if (nline == "目录" || nline == "目次")
                {
                    fromIndex = i;
                    for (var j = i; j < i + 100 && j < m_currentContent.ContentLines.Length; j++)
                    {
                        stringBuilder.Append(line);
                    }
                    break;
                }
            }
            if (stringBuilder.Length == 0)
            {
                MessageBox.Show("没有找到目录");
                return new int[] { -1, -1 };
            }
            var str= OllamaUtils.SendChatRequest("下面是一个文档的目录，你告诉目录截止到第几行，请之间告诉我行号，不需要别的。\r\n文档内容是:" + stringBuilder.ToString());
            return new int[]
            {
                fromIndex,int.Parse(str)
            };
        }
    }
}
